package team.fourth.combat.service;

import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import team.fourth.combat.dao.MemberDao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    MemberDao memberDao;
    @Override
    public List<Integer> getMemberReport(List<String> months) {
        //返回数据结果集
        List<Integer> memberCount = new ArrayList<>();

        //循环months条件一个月一个月统计（能不能批量统计呀，可以的，就把months一次性传入然后sql需要按照月份分组统计，可以得到每个月的会员数量，然后在代码里面构建增长趋势）
        for (String month : months) {//month 2020-02
            month = month + "-31";
            Integer count = memberDao.getMemberReport(month);
            memberCount.add(count);
        }
        return memberCount;
    }

    @Override
    public List<Map> getSetmealReport() {
        return memberDao.getSetmealReport();
    }
}
